package ru.pashkan.perspectives;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;

import org.springframework.stereotype.Component;
import ru.pashkan.perspectives.elements.ShowMainMenu;
import ru.pashkan.perspectives.elements.SitesListTable;

@Component
public class SitesListViewer{

    private Composite parent;
    public static Display display;

    public Shell createShell() {

        Display display = Display.getDefault();
        Shell shell = new Shell(display, SWT.SHELL_TRIM);
        shell.open();
        createPartControl(shell);

        return shell;
    }

    public void runShell(){
        final Display display = new Display();
        this.display = display;

        Shell shell = new SitesListViewer().createShell();

        ShowMainMenu showMainMenu = new ShowMainMenu(display);
        SitesListTable sitesListTable = new SitesListTable(display);

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

    private void setShellSettings(Shell shell) {
        shell.setBounds(200, 200, 824, 750);
    }

    public void createPartControl(Composite composite) {
        this.parent = composite;

        Device device = Display.getCurrent ();
        Color green = new Color (device, 165, 211, 150);
        parent.setBackground(green);

        GridLayout gl_composite = new GridLayout(1, false);
        gl_composite.horizontalSpacing = 0;
        gl_composite.marginHeight = 0;
        gl_composite.verticalSpacing = 0;
        gl_composite.marginWidth = 0;
        parent.setLayout(gl_composite);
    }
}